//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This Stata DO file with the corresponding dataset EconLetters.dta replicate all the tables in the paper: 		//
// Escobari, Diego. "Systematic Peak-load Pricing, Congestion Premia and Demand Diverting: Empirical Evidence."		//
// Economics Letters, 103 (1), April 2009, 59-61.																   	//
// Please cite the paper if you use these data in your own reseach.													//
// This code requires the following add-ins: outreg2 																//
// Please e-mail me if you have any questions: escobaridiego@gmail.com												//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

mata
mata clear
end
clear matrix
clear
set memory 50m
set maxvar 2048 
set more off
set matsize 1000

// Change the following folder to where the EconLetters.dta data is located

cd "Z:\Documents(UseThisOne)\Publications\2009EconLetters\Stata"

use EconLetters, clear

// Set panel structure

xtset flightid timeid

tsset flightid timeid

// Generate additional variables

gen      thkgiv = 0
replace  thkgiv = 1 if date == "22-Nov"

gen lfare = log(fare)

gen dayadvsq = dayadv^2
gen dayadvcu = dayadv^3

// Label variables

label variable load 	"LOAD"
label variable thkgiv 	"THKGIV"
label variable lfare 	"LogFARE"
label variable dayadvsq "DAYADVSQ"
label variable dayadvcu "DAYADVCU"

// Table 1

sum fare thkgiv load dayadv tue

outreg2 	fare thkgiv load dayadv tue using Table01, word auto(3) sum(log) eqdrop(N) sortvar(fare thkgiv load dayadv tue) raw noni label replace

// Table 2

xi: reg lfare 	thkgiv 		dayadv 						tue i.flightid, robust
local F  = (e(r2)/(e(df_m))) / ((1-e(r2))/(e(N)-e(df_m)-1))
outreg2   		thkgiv 		dayadv					    tue	using Table02, word auto(3) stats(coef tstat) symbol(***,**,*) nocons noobs addstat(R2, e(r2), F, `F') noni nor2 label nonotes replace

xi: reg lfare 	thkgiv 		dayadv dayadvsq 			tue i.flightid, robust
local F  = (e(r2)/(e(df_m))) / ((1-e(r2))/(e(N)-e(df_m)-1))
outreg2   		thkgiv 		dayadv dayadvsq 			tue using Table02, word auto(3) stats(coef tstat) symbol(***,**,*) nocons noobs addstat(R2, e(r2), F, `F') noni nor2 label nonotes

xi: reg lfare 	thkgiv 		dayadv dayadvsq dayadvcu 	tue i.flightid, robust
local F  = (e(r2)/(e(df_m))) / ((1-e(r2))/(e(N)-e(df_m)-1))
outreg2   		thkgiv 		dayadv dayadvsq dayadvcu 	tue using Table02, word auto(3) stats(coef tstat) symbol(***,**,*) nocons noobs addstat(R2, e(r2), F, `F') noni nor2 label nonotes

xi: reg lfare 	thkgiv load dayadv 						tue i.flightid, robust
local F  = (e(r2)/(e(df_m))) / ((1-e(r2))/(e(N)-e(df_m)-1))
outreg2   		thkgiv load dayadv 						tue using Table02, word auto(3) stats(coef tstat) symbol(***,**,*) nocons noobs addstat(R2, e(r2), F, `F') noni nor2 label nonotes

xi: reg lfare 	thkgiv load dayadv dayadvsq 			tue i.flightid, robust
local F  = (e(r2)/(e(df_m))) / ((1-e(r2))/(e(N)-e(df_m)-1))
outreg2   		thkgiv load dayadv dayadvsq 			tue using Table02, word auto(3) stats(coef tstat) symbol(***,**,*) nocons noobs addstat(R2, e(r2), F, `F') noni nor2 label nonotes

xi: reg lfare 	thkgiv load dayadv dayadvsq dayadvcu 	tue i.flightid, robust
local F  = (e(r2)/(e(df_m))) / ((1-e(r2))/(e(N)-e(df_m)-1))
outreg2   		thkgiv load dayadv dayadvsq dayadvcu 	tue using Table02, word auto(3) stats(coef tstat) symbol(***,**,*) nocons noobs addstat(R2, e(r2), F, `F') noni nor2 label nonotes sortvar(thkgiv load dayadv dayadvsq dayadvcu tue)


